# Calculate percentage of women
df_summary <- clean_LISS_data %>%
  filter(woman == 1) %>%                     # Filter for women
  group_by(sector) %>%                       # Group by sector
  summarise(count = n(), .groups = 'drop') %>% # Count number of women in each sector
  mutate(percent = count / sum(count))  # Calculate percentage of women in each sector

# Drop smallest sectors
df_summary_w <- df_summary %>% filter(count > 15) %>% filter(!is.na(sector))

# Labels
sector_labels <- c(
  "Production", "Retail", "Catering", "Transport", "Finance", "Business", "Public", "Education", "Healthcare", "Environment", "Other"
)

df_summary_w <- df_summary_w %>%
  mutate(dbl = 1:11) %>%
  mutate(lbl = factor(dbl, levels = 1:11, labels = sector_labels))

# Plot
plot_sector <- ggplot(df_summary_w, aes(x = lbl, y = percent)) + theme_bw() +
  geom_bar(stat = "identity", fill = "grey85", color = "black") +  # stat = "identity" for using actual values
  labs(
    x = "",
    y = "Fraction of Women Employed"
  ) +
  theme(
    legend.key = element_rect(fill = "white", colour = "white"), 
    legend.position =  "bottom", 
    legend.box = "horizontal", 
    legend.text = element_text(size = 12),
    axis.text.x = element_text(size = 14, color = "black", angle = 45, hjust = 1),  # Increase x-axis label size
    axis.title.y = element_text(size = 14),  # Increase x-axis label size
    axis.text.y = element_text(size = 14, color = "black"),  # Increase y-axis label size
    axis.ticks.x = element_blank()  # Remove x-axis ticks
  ) 


save_PlotSectors <- file.path(graph_dir, "EmploymentSectors.pdf")

# Save as PNG
pdf(save_PlotSectors)
print(plot_sector)
dev.off()  